﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ComplexNetGeneratorLib
{
    public class ComplexNet
    {
        public List<ComplexNetNode> nodes;
        public List<ComplexNetEdge> edges;
        
        public ComplexNet()
        {
            nodes = new List<ComplexNetNode>();
            edges = new List<ComplexNetEdge>();
        }

        public void saveAsGraphML(StreamWriter writer)
        {
            writer.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
            writer.WriteLine("<graphml xmlns=\"http://graphml.graphdrawing.org/xmlns\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd\">");
            writer.WriteLine("\t<graph id=\"G\" edgedefault=\"undirected\">");
            
            foreach (ComplexNetNode node in nodes)
            {
                writer.WriteLine("\t\t<node id=\"" + node.id + "\" />");
            }

            foreach (ComplexNetEdge edge in edges)
            {
                writer.WriteLine("\t\t<edge id=\"" + edge.id + "\" source=\"" + edge.source.id + "\" target=\"" + edge.target.id + "\" />");
            }

            writer.WriteLine("\t</graph>");
            writer.WriteLine("</graphml>");
        }
    }
}
